﻿<Page
    x:Class="EmprestaAE.MVVM.View.BorrowView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:EmprestaAE.MVVM.View"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:viewmodel="using:EmprestaAE.MVVM.ViewModel"
    xmlns:attached="using:EmprestaAE.Common.AttachedProperties"
    xmlns:converters="using:EmprestaAE.Common"
    xmlns:view="using:EmprestaAE.MVVM.View"
    mc:Ignorable="d">

    <!--<Page.Transitions>
        <TransitionCollection>
            <EntranceThemeTransition/>
        </TransitionCollection>
    </Page.Transitions>-->

    <Page.Resources>
        <viewmodel:BorrowVM x:Key="borrowvm"/>
        <converters:ConverterDateToString x:Key="DateToStringConverter"/>
    </Page.Resources>

    <Grid Background="{StaticResource PageBorrowBackgroundColor}"
          DataContext="{Binding Source={StaticResource borrowvm}, Path=Instance}">
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="6*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>

        <!-- back button -->
        <Grid Grid.Column="0" 
              Grid.Row="0">
            <Button Style="{StaticResource BackButtonStyle}"
                    Grid.Row="0"
                    Grid.Column="0"
                    Command="{Binding NavigationService.GoBackCommand}">
            </Button>
        </Grid>

        <!-- title -->
        <Grid Grid.Row="0"
              Grid.Column="1">
            <TextBlock Style="{StaticResource PageHeaderTextStyle}"
                       Text="{StaticResource BorrowViewTitle}"
                       Grid.Column="1"
                       Grid.Row="0"/>
        </Grid>

        <!-- content -->
        <Grid Grid.Column="1"
              Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="8*"/>
                <ColumnDefinition Width="8*"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="8*"/>
                <RowDefinition Height="8*"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>

            <!-- what picker-->
            <Grid Grid.Column="0"
                  Grid.Row="0"
                  Margin="20">
                <Button x:Name="button_whatpicker" Style="{StaticResource S_ButtonPicker}"                        
                        Command="{Binding CaptureWhatCommand}"                        
                        CommandParameter="{Binding RelativeSource={RelativeSource Self}}"                        
                        attached:Images.NormalImage="/Resources/Images/emprestaae_camera.png"
                        attached:Images.PressedImage="/Resources/Images/emprestaae_camera_pressed.png"
                        attached:Images.ImageVisibility="{Binding WhatImagePickered, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter='Revert'}">
                    <Grid x:Name="c">
                        <Image Source="{Binding WhatImage.Source}"
                               Width="{Binding ElementName=contentpresenter, Path=ActualHeight}"
                               Height="{Binding ElementName=contentpresenter,Path=ActualHeight}"
                       
                       HorizontalAlignment="Left"/>
                        <StackPanel Orientation="Horizontal"
                                    HorizontalAlignment="Right">
                            <TextBlock Style="{StaticResource S_TextBlockButtonPicker}"
                                       Text="isto"
                                       Visibility="{Binding WhatImagePickered, Converter={StaticResource BoolToVisibilityConverter}}"/>
                            <TextBlock Style="{StaticResource S_TextBlockButtonPicker}"
                                       Text="o que?"
                                       Visibility="{Binding WhatImagePickered, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter='Revert'}"/>
                        </StackPanel>
                    </Grid>
                </Button>
                
            </Grid>

            <!-- due date data picker-->
            <Grid Grid.Column="1"
                  Grid.Row="0"
                  Margin="20">
                <Button Style="{StaticResource S_ButtonPicker}"
                        Command="{Binding NavigationService.NavigateCommand}"
                        attached:Images.NormalImage="/Resources/Images/emprestaae_calendar.png"
                        attached:Images.PressedImage="/Resources/Images/emprestaae_calendar_pressed.png"
                        attached:Images.ImageVisibility="{Binding DatePickered, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter='Revert'}">
                    <Button.CommandParameter>
                        <view:DatePickerView/>
                    </Button.CommandParameter>
                    <Grid>
                        <TextBlock Style="{StaticResource S_TextBlockButtonPicker}"
                                   Visibility="{Binding DatePickered, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter='Revert'}"
                                   Text="até quando?"/>
                        <StackPanel Orientation="Horizontal" VerticalAlignment="Bottom" HorizontalAlignment="Right">
                            <TextBlock Style="{StaticResource S_TextBlockButtonPicker}"
                                   Visibility="{Binding DatePickered, Converter={StaticResource BoolToVisibilityConverter}}"
                                   Text="até "/>
                            <TextBlock Style="{StaticResource S_TextBlockButtonPicker}"
                                   Visibility="{Binding DatePickered, Converter={StaticResource BoolToVisibilityConverter}}"
                                   Text="{Binding Date, Converter={StaticResource DateToStringConverter}}"/>
                        </StackPanel>
                    </Grid>
                </Button>
            </Grid>
            
            <Grid Grid.Column="0"
                  Grid.Row="1"
                  Margin="20">

                <Button Style="{StaticResource S_ButtonPicker}"
                        Command="{Binding SelectContactCommand}"
                        CommandParameter="{Binding RelativeSource={RelativeSource Self}}"
                        attached:Images.NormalImage="/Resources/Images/emprestaae_user.png"
                        attached:Images.PressedImage="/Resources/Images/emprestaae_user_pressed.png"
                        attached:Images.ImageVisibility="{Binding ContactImagePickered, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter='Revert'}">
                    <Grid>
                        <Image Source="{Binding ContactImage.Source}"
                       Stretch="Uniform"
                       HorizontalAlignment="Left"/>
                        <StackPanel Orientation="Horizontal"
                                    HorizontalAlignment="Right">
                            <TextBlock Style="{StaticResource S_TextBlockButtonPicker}"
                                   Text="{Binding ContactName}"
                                       Visibility="{Binding ContactImagePickered, Converter={StaticResource BoolToVisibilityConverter}}"/>
                            <TextBlock Style="{StaticResource S_TextBlockButtonPicker}"
                                       Visibility="{Binding ContactImagePickered, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter='Revert'}"
                                   Text="pra quem?"/>
                        </StackPanel>
                    </Grid>
                </Button>

            </Grid>
            

            <!-- borrow -->
            <Grid Grid.Column="1"
                  Grid.Row="1"                  
                  Margin="20">

                <Button Style="{StaticResource S_ButtonPicker}"
                        IsEnabled="{Binding LendEnable}"
                        Command="{Binding BorrowCommand}"
                        HorizontalAlignment="Center"
                        attached:Images.NormalImage="/Resources/Images/emprestaae_okborrow.png"
                        attached:Images.PressedImage="/Resources/Images/emprestaae_okborrow_pressed.png">
                </Button>
            </Grid>

        </Grid>
    </Grid>
</Page>